package 第八次字典;
import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JTextArea;
import java.awt.event.ActionListener;
import java.util.AbstractList;
import java.util.Iterator;
import java.util.LinkedList;
import java.awt.event.ActionEvent;
public class Huyi extends JFrame {

	private JPanel contentPane;
	private JTextField input;
	
	private LinkedList<Record> content=new LinkedList<>();
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Huyi frame = new Huyi();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Huyi() {
		Record r[]=new Record[2];
		r[0]=new Record("thank","лл");
		r[1]=new Record("bye","ټ");
		for(Record i:r)
			content.add(i);
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		input = new JTextField();
		input.setBounds(37, 34, 235, 28);
		contentPane.add(input);
		input.setColumns(10);
		
		JTextArea output = new JTextArea();
		output.setBounds(37, 72, 235, 161);
		contentPane.add(output);
		JButton search = new JButton("search");
		search.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String str= input.getText();
				String regex="[A-Za-z|\\u4e00-\\u9fa5]+";
				if(str.matches(regex)) {
					Iterator<Record> it=content.iterator();
					Iterator<Record> has=content.iterator();
					Record re,ea ;
					boolean flag = true;
					while(it.hasNext()) {
						re=it.next();
						if(re.english.equals(str)) {
							flag=false;
						output.setText(re.chinese);
						}
						}
											
					//Ӣ
					
					while(has.hasNext()) {
						ea=has.next();
						if(ea.chinese.equals(str)) {
							flag=false;
						output.setText(ea.english);
						}
						}
					if(flag) {
						output.setText("no saerch");
					}
				}
				
			}
		});
		search.setBounds(310, 33, 100, 29);
		contentPane.add(search);
		
		
	}
}
/*import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Window;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
i/**/
